import React, { Component } from 'react'
import { Route, Switch } from 'dva/router';

export default class RouterView extends Component {


    static defaultProps = {
        routes: []
    }

    render() {
        const { routes } = this.props
        return (
            <Switch>
                {
                    routes.map(item => {
                        return (
                            <Route path={item.path} key={item.path} render={(...rest) => {
                                if(item.component){
                                    return (
                                        <item.component>
                                            {item.children && item.children.length >= 1 ? <RouterView routes={item.children} /> : ''}
                                        </item.component>
                                    )
                                }else if(item.children && item.children.length >= 1){
                                    return <RouterView routes={item.children} />
                                }
                            }} />
                        )
                    })
                }
            </Switch>
        )
    }
}
